<template>
  <Card title="每月到款与新签订合同额" :loading="loading">
    <div ref="chartRef" :style="{ width, height }"></div>
  </Card>
</template>
<script lang="ts">
import { defineComponent, Ref, ref, watch } from 'vue';
import { Card } from 'ant-design-vue';
import { useECharts } from '/@/hooks/web/useECharts';

export default defineComponent({
  components: { Card },
  props: {
    loading: Boolean,
    chartData: {
      type: Object,
      required: true,
    },
    width: {
      type: String as PropType<string>,
      default: '100%',
    },
    height: {
      type: String as PropType<string>,
      default: '300px',
    },
  },
  setup(props) {
    const chartRef = ref<HTMLDivElement | null>(null);
    const { setOptions } = useECharts(chartRef as Ref<HTMLDivElement>);
    watch(
      () => props.loading,
      () => {
        if (props.loading) {
          return;
        }
        setOptions({
          legend: {
            bottom: 0,
            data: ['到款', '新签订合同额'],
          },
          tooltip: {},
          radar: {
            radius: '60%',
            splitNumber: 8,
            indicator: [
              { text: '1月', }, { text: '2月', }, { text: '3月', }, { text: '4月', }, { text: '5月', }, { text: '6月', },
              { text: '7月', }, { text: '8月', }, { text: '9月', }, { text: '10月', }, { text: '11月', }, { text: '12月', },
            ],
          },
          series: [
            {
              type: 'radar',
              symbolSize: 0,
              areaStyle: {
                shadowBlur: 0,
                shadowColor: 'rgba(0,0,0,.2)',
                shadowOffsetX: 0,
                shadowOffsetY: 10,
                opacity: 1,
              },
              data: [
                {
                  value: props.chartData.monthDataNewContract,
                  name: '新签订合同额',
                },
                {
                  value: props.chartData.monthDataReceived,
                  name: '到款',
                },
              ],
            },
          ],
        });
      },
      { immediate: true }
    );
    return { chartRef };
  },
});
</script>
